package com.stx.bms.web;

import com.stx.bms.dao.BlogDAO;
import com.stx.bms.dao.BlogDAOImpl;
import com.stx.bms.entity.Blog;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/blog")
public class BlogViewServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求传过来参数(博客ID)
        String id = request.getParameter("id");

        //查一条博客信息
        BlogDAO dao = new BlogDAOImpl();
        Blog blog = dao.viewById( Integer.parseInt(id) );

        //暂存查到的数据(request)
        request.setAttribute("blog", blog);

        //请求转发到查看页面
        request.getRequestDispatcher("view.jsp").forward(request, response);

    }
}
